﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace XNASpelProjekt
{
    /// <summary>
    /// Base class for non-jumping enemies
    /// </summary>
    public abstract class EnemyActor : Actor
    {
        #region Member Variables

        protected enum _state { underwater, movingUp, shooting, movingDown, dying }    //fiendens möjliga tillstånd
        protected _state state;                                                        //fiendens nuvarande tillstånd

        protected int destx, desty;         //destination x,y
        protected int stateTime;            //innehåller tiden som passerat i nuvarande tillstånd
        protected int stateTimeLimit;       //används som gräns för när ett tillstånd uppdateras
        protected bool stateSet;            //true - när nuvarande tillstånd har initierats; false - när nästa tillstånd ska initieras
        protected Random rnd;               //slumptalsgenerator

        public int Health { get; set; }     //Fiendens hälsa
        public int CollisionDamage { get; set; }

        #endregion

        #region constructors
        /// <summary>
        /// Base constructor
        /// </summary>
        /// <param name="texture">The enemy's texture</param>
        /// <param name="x">(Optional) The enemy's x-position</param>
        /// <param name="y">(Optional) The enemy's y-position</param>
        /// <param name="facing">(Optional) The enemy's facing</param>
        /// <param name="hidden">(Optional) A hidden enemy will not be drawn to screen</param>
        protected EnemyActor(Texture2D texture, int x = 0, int y = 0, _Facing facing = _Facing.right, bool hidden = true)
            : base(texture, x, y, facing, hidden)
        {
        }

        #endregion

        #region protected methods

        protected virtual void changeState(_state s)
        {

        }

        #endregion

        #region public methods
        
        /// <summary>
        /// Inflicts damage to the enemy
        /// </summary>
        /// <param name="damage">The amount of damage inflicted</param>
        public virtual void damage(int damage, int damagetype = 0)
        {
            Game1.damageSound.Play();
            Health -= damage;
            Hidden = true;

            if (Health <= 0)
            {
                changeState(_state.dying);
            }
        }

        #endregion
    }
}
